import {Express} from "express";
import {SystemUtil} from "../utils/SystemUtil";

export function SystemService(app: Express) {
  const prefix = '/api/system';

  // 打开目录
  app.post(prefix + '/openDir', (req, res) => {
    const {path} = req.body;
    try {
      // 实现打开目录
      SystemUtil.openDir(path).then(() => {
        res.json({success: true, message: `已打开目录: ${path}`});
      }).catch((error) => {
        console.error(`无法打开目录: ${error.message}`);
        res.status(500).json({error: `无法打开目录: ${error.message}`});
      });
    } catch (error) {
      console.error('打开目录失败:', error);
      res.status(500).json({error: `服务器错误: ${(error as Error).message}`});
    }
  });
}

